package math2.delaunay;

import java.util.LinkedList;
import java.util.List;

/**
 * Note: Delaunay1 didn't work correctly for this example: d.addPoint(-1, -1);
 * d.addPoint(1, -1); d.addPoint(1, 1); d.addPoint(-1, 1); d.addPoint(-1, -0.2);
 * d.addPoint(1, 0.2); d.addPoint(0.0, 0.0);
 * 
 * @author hbui
 * 
 */
public class Delaunay1 extends AbstractDelaunay {

	private List<Point> points;

	public Delaunay1() {
		points = new LinkedList<Point>();
	}

	public void addPoint(Point p) {
		points.add(p);
	}

	public List<Point> getPoints() {
		return points;
	}

	public List<Triangle> getTriangles() {
		List<Triangle> T = new LinkedList<Triangle>();
		int n = points.size();
		for (int i = 0; i < n; i++) {
			for (int j = i; j < n; j++) {
				for (int k = j; k < n; k++) {
					Triangle t = new Triangle(points.get(i), points.get(j), points.get(k));
					if (this.isDelaunay(t)) {
						T.add(t);
					}
				}
			}
		}
		return T;
	}

	private boolean isDelaunay(Triangle t) {
		boolean id = true;
		for (Point p : points)
			id &= !t.isInsideCCM(p);
		return id;
	}

}
